$(function() {
	var btns = {};
	$(".checkbox").simpleSwitch({
		"theme": "DefaultMin"
	});
	//给所有字段设置初始值
	$(".feild").each(function(){
		//获取字段属性的类型
		var type = $(this).attr("type");
		//判断类型
		window[type+"Init"]($(this));
	});
});
function checkboxInit($elem){
	var feild = $elem.attr("feild");
	//按照switch设置值
	var value = string2Bool(localStorage[feild]);
	$elem.setSwitch(value);
	$elem.change(function(){
		var feild = $elem.attr("feild");
		var value = $(this).getValue();
		localStorage[feild]=bool2String(value);
	});
}
function textInit($elem){
	var feild = $elem.attr("feild");
	//按照switch设置值
	var value = localStorage[feild];
	$elem.val(value);
	$elem.change(function(){
		var feild = $elem.attr("feild");
		var value = $(this).val();
		localStorage[feild]=value;
	});
}

function bool2String(b){
	return b?"true":"false"
}
function string2Bool(s){
	return s=="true";
}

